<?php

class RazaController extends BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		$razas = Raza::orderBy('id','DESC')->get();
		return View::make('razas.index')->with('razas',$razas);
	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		return View::make('razas.create');
	}


	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		$raza = new Raza;
		$raza->raza = Input::get('raza');
		$raza->descripcion = Input::get('descripcion');
		if($raza->save()){
			Session::flash('message','Guardado Correctamente');
			Session::flash('class','success');
		}else{
			Session::flash('message','Ha ocurrido un error');
			Session::flash('class','danger');
		}
		return Redirect::to('razas');
	}


	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id = null)
	{
		$raza = Raza::find($id);
		return View::make('razas.show')->with('raza',$raza);
	}


	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id = null)
	{
		$raza = Raza::find($id);
		return View::make('razas.edit')->with('raza',$raza);
	}


	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		$raza = Raza::find($id);
		$raza->raza = Input::get('raza');
		$raza->descripcion = Input::get('descripcion');
		if($raza->save()){
			Session::flash('message','Actualizado Correctamente');
			Session::flash('class','success');
		}else{
			Session::flash('message','Ha ocurrido un error');
			Session::flash('class','danger');
		}
		return Redirect::to('razas');
	}


	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		$raza = Raza::find($id);
		if($raza->delete()){
			Session::flash('message','Eliminado Correctamente');
			Session::flash('class','success');
		}else{
			Session::flash('message','Ha ocurrido un error');
			Session::flash('class','danger');
		}
		return Redirect::to('razas');
	}


}
